package com.alibaba.otter.manager.biz.autoconfigure.properties;

import com.alibaba.otter.manager.biz.autoconfigure.OtterPropertySourceFactory;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.nio.charset.StandardCharsets;

@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = "otter")
@PropertySource(value = "classpath:otter.properties", factory = OtterPropertySourceFactory.class)
public class ManagerProperties {

    private String domainName = "127.0.0.1";

    private Manager manager = new Manager();

    private Monitor monitor = new Monitor();

    private Zookeeper zookeeper = new Zookeeper();

    private Communication communication = new Communication();

    private Database database = new Database();



    @Setter
    @Getter
    public static class Communication {

        public static final Integer DEFAULT_PAYLOAD = 8388608;

        public static final Integer DEFAULT_POOL_SIZE = 10;

        public static final Integer DEFAULT_MANAGER_PORT = 1099;

        private Integer payload = DEFAULT_PAYLOAD;

        private Integer poolSize = DEFAULT_POOL_SIZE;

        private Integer port = DEFAULT_MANAGER_PORT;
    }

    @Getter
    @Setter
    public static class Database{

        private String driverClass;

        private String url;

        private String username;

        private String password;
    }


    @Setter
    @Getter
    public static class Zookeeper {

        /**
         * 60s
         */
        public static final Integer DEFAULT_SESSION_TIMEOUT = 60000;

        public static final String DEFAULT_CLUSTER = "localhost:2181";

        private String cluster = DEFAULT_CLUSTER;

        private Integer sessionTimeout = DEFAULT_SESSION_TIMEOUT;
    }


    @Setter
    @Getter
    public static class Manager {


        /**
         * otter arbitrate connect manager config
         */
        private String address;

        private Boolean productionMode = Boolean.TRUE;

        private Monitor monitor = new Monitor();

    }

    @Setter
    @Getter
    @Configuration
    @ConfigurationProperties(prefix = "otter.manager.monitor")
    public static class Monitor {

        /**
         * self-monitor enable or disable
         */
        private Boolean selfEnabled = Boolean.TRUE;
        /**
         * self-monitor interval , default 120s
         */
        private Integer selfInterval = 120;
        /**
         * auto-recovery paused enable or disable
         */
        private Boolean recoveryPaused = Boolean.TRUE;
        /**
         *  manager email user config
         */
        private Email email = new Email();
    }


    @Setter
    @Getter
    @Configuration
    public static class Email {


        private String host;

        private String username;

        private String password;

        private Smtp smtp = new Smtp();

        private String encoding = StandardCharsets.UTF_8.name();

    }

    @Setter
    @Getter
    public static class Smtp {

        private Integer port;
    }
}
